//
//  SSMainViewController.swift
//  weibooo
//
//  Created by  sulcan on 16/4/8.
//  Copyright © 2016年 苏烁. All rights reserved.
//

import UIKit

class SSMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let mainTabBar = SSMainTabBar()
        
        setValue(mainTabBar, forKey: "tabBar")
        
        mainTabBar.composeClosure = { () -> Void in
            SSPrint("加号按钮被点击了")
        }
        
        setupChildVCs();
    }
    
    func setupChildVCs() {
        addChildVC(controller: SSHomeViewController(), imageName: "tabbar_home", title: "首页")
        
        addChildVC(controller: SSMessageViewController(), imageName: "tabbar_message_center", title: "消息")
        
        addChildVC(controller: SSDiscoverViewController(), imageName: "tabbar_discover", title: "发现")
        
        addChildVC(controller: SSProfileViewController(), imageName: "tabbar_profile", title: "我")
        
    }
    
    func addChildVC(controller controller: UIViewController, imageName: String, title: String) {
        // 设置标题
        controller.tabBarItem.title = title
        // 设置普通图片
        controller.tabBarItem.image = UIImage(named: imageName)
        // 设置选中图片
        controller.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        // 设置标题颜色
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
        // 包装一个导航控制器，并添加到tabBarVC中
        addChildViewController(UINavigationController(rootViewController: controller))
    }
}
